package com.example.dynamicproxydemo;

import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyInvocationHandler implements InvocationHandler{
    private Object target;

    public void setTarget(Object target) {
        this.target = target;
    }
    //得到代理类
    public Object getProxy(){
        return Proxy.newProxyInstance(this.getClass().getClassLoader(), target.getClass().getInterfaces(), (java.lang.reflect.InvocationHandler) this);
    }
    public Object invoke(Object proxy, Method method,Object[] args)throws Throwable{
        return method.invoke(target,args);
    }
}
